package com.yylany.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yylany.mapper.HouseMapper;
import com.yylany.mapper.HouseUserMapper;
import com.yylany.pojo.House;
import com.yylany.pojo.HouseUser;
import com.yylany.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * User  yyl
 * Description: house
 * Created by yaoyonglong on 2018/11/5 20:19
 */
@Service
public class HouseServiceImpl implements HouseService {

    @Autowired
    private HouseMapper houseMapper;

    @Autowired
    private HouseUserMapper houseUserMapper;


    @Override
    public List<House> getHotHouse(Integer recomSize) {
        Example example = new Example(House.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("beds", recomSize);
        List<House> houses = houseMapper.selectByExample(example);
        return houses;
    }

    @Override
    public List<House> getAllHouse() {
        return houseMapper.selectAll();
    }

    @Override
    public List<House> queryHouse(House query, Integer pageSize, Integer pageNum) {

        PageHelper.startPage(pageNum, pageSize);
        Example example = new Example(House.class);
        Example.Criteria criteria = example.createCriteria();

        criteria.andEqualTo("type", query.getType());
        List<House> houses = houseMapper.selectByExample(example);
        PageInfo<House> housePageInfo = new PageInfo<>(houses);
        return housePageInfo.getList();

    }

    @Override
    public House queryOneHouse(Long id) {
        return houseMapper.selectByPrimaryKey(id);
    }

    @Override
    public HouseUser getHouseUser(Long id) {
        return houseUserMapper.selectByPrimaryKey(id);
    }
}
